import requests,json,time

my_cookie=input('请打开 https://taodaxiang.com/category 获取浏览器cookie粘贴到这里')
header={
    "Accept": "image/webp,image/apng,image/*,*/*;q=0.8",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
    "Connection": "keep-alive",
    "Cookie": my_cookie,
    "DNT": "1",
    "Host": "taodaxiang.com",
    "Referer": "https://taodaxiang.com/category",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
    'X-Requested-With': 'XMLHttpRequest'
        }

input_id=input('請輸入商品ID,多個請用逗號隔開')
#把用户输入转化成list
id_list=input_id.split(',')
def get_info(i):
    time.sleep(2)
    from_data = {'ids[]': i}
    url = 'https://taodaxiang.com/category/index/get'
    response=requests.post(url, data=from_data, headers=header)
    try:
        print(response.json()[0]['cat_id'] + '\t' + response.json()[0]['url'] + '\t' + response.json()[0]['cat_name'])
        return
    except:
        time.sleep(3)
        get_info(i)

for i in id_list:
    response=get_info(i)


